

package com.hazelcast.access;

import javax.annotation.Nonnull;
import javax.security.auth.login.LoginException;

/**
 * Service for pluggable authentication and authorization.
 */
public interface AccessControlService {

    /**
     * Authenticates user described by given {@link AuthenticationContext} and returns role names assigned.
     *
     * @param ctx authentication context
     * @return array of role names assigned to authenticated user
     * @throws LoginException authentication fails
     */
    @Nonnull
    String[] authenticate(@Nonnull AuthenticationContext ctx) throws LoginException;

    /**
     * Returns {@code true} when access to resource described in the {@link AuthorizationContext} should be granted to assigned
     * roles. The role names are typically the ones returned by the {@link #authenticate(AuthenticationContext)} method call.
     *
     * @param ctx           authorization context
     * @param assignedRoles role names to be checked for access to the resource
     * @return {@code true} when the access is granted
     */
    boolean isAccessGranted(@Nonnull AuthorizationContext ctx, @Nonnull String... assignedRoles);
}
